﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Navigation.Regions;
using Rafy.Domain;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Rafy.Book.ViewModels
{
    public class BookPageViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;


        private string _selectedPage;
        public string SelectedPage
        {
            get => _selectedPage;
            set => SetProperty(ref _selectedPage, value);
        }

        private List<Base_Books> _books;
        public List<Base_Books> Books
        {
            get => _books;
            set => SetProperty(ref _books, value);
        }

        public DelegateCommand<Base_Books> NavigateCommand { get; private set; }
        public BookPageViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;
            // 初始化命令
            NavigateCommand = new DelegateCommand<Base_Books>(NavigateToPage);

            LoadData();
        }

        private void LoadData()
        {
            var repo = RF.ResolveInstance<Base_BooksRepository>();
            Books = repo.GetAll().ToList();
        }

        private void NavigateToPage(Base_Books book)
        {
            SelectedPage = book.F_NavPage;  // 记录选中的学科

            var param = new NavigationParameters { { "bookId", book.Id } };
            _regionManager.RequestNavigate("TempContentRegion", book.F_NavPage, param);
        }
    }
}
